package com.kk.flink;

import org.apache.flink.api.java.tuple.Tuple2;
import org.apache.flink.streaming.api.datastream.DataStream;
import org.apache.flink.streaming.api.datastream.SingleOutputStreamOperator;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;

/**
 * @author liukang
 * @since 2021/12/1 20:46
 */
public class WordStreamCount {

    public static void main(String[] args) throws Exception {
        StreamExecutionEnvironment environment = StreamExecutionEnvironment.getExecutionEnvironment();

        //设置并发数 实际生产中是分布式的分区数据
        environment.setParallelism(6);

        //从文件中读取数据
        String inputPath = "C:\\Users\\kk_master001\\IdeaProjects\\BigData\\FlinkDemo\\src\\main\\resources\\hello.txt";

        DataStream<String> streamSource = environment.readTextFile(inputPath);

        DataStream<Tuple2<String, Integer>> resultStream = streamSource
                .flatMap(new WordCount.MyflatMapper())
                .keyBy(0)
                .sum(1);

        resultStream.print();

        environment.execute();
    }
}
